package com.flyox.game.fivetiger.view;

import java.awt.CardLayout;
import java.io.BufferedReader;
import java.io.InputStreamReader;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;

/**
 * 帮助对话框
 * 
 * @author sunwei
 * 
 */
public class HelpJDialog extends javax.swing.JDialog {

	private static final long serialVersionUID = 8055332440746863078L;
	private JTextPane jTextPaneHelp;
	private JScrollPane jScrollPaneHelp;

	public HelpJDialog(JFrame frame) {
		super(frame, false);
		initGUI();
	}

	private void initGUI() {
		try {
			CardLayout thisLayout = new CardLayout();
			getContentPane().setLayout(thisLayout);
			{
				jScrollPaneHelp = new JScrollPane();
				getContentPane().add(jScrollPaneHelp, "North");
				{
					jTextPaneHelp = new JTextPane();
					jScrollPaneHelp.setViewportView(jTextPaneHelp);
					jTextPaneHelp.setAutoscrolls(true);

//					String strURL = HelpJDialog.class.getResource("/").toString();
//					String filePath = strURL.substring(strURL.indexOf("/") + 1, strURL.lastIndexOf("/")) + "/com/flyox/game/fivetiger/res/readme.txt";
//					
					BufferedReader br = new BufferedReader(new InputStreamReader(getClass().getClassLoader().getResourceAsStream("com/flyox/game/fivetiger/res/readme.txt"), "UTF-8"));

					StringBuffer sb = new StringBuffer();
					String line;
					while ((line = br.readLine()) != null) {
						sb.append(line + "\n");
					}
					br.close();
					jTextPaneHelp.setText(sb.toString());
				}
			}
			setSize(400, 600);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
